<?php namespace Phpcmf\Controllers\Admin;

class Home extends \Phpcmf\App
{
    //admin.php?s=attachment&c=home&m=index
	public function index() {

	    $name = 'hello word';

        // 将变量传入模板
        \Phpcmf\Service::V()->assign([
            'testname' => $name,
        ]);
        // 选择输出模板 后台位于 ./Views/test.html 此文件已经创建好了
        \Phpcmf\Service::V()->display('index.html');
    }
//    获得文件列表
//admin.php?s=attachment&c=home&m=get_file_list
    public function  get_file_list(){
	    if (isset($_GET['parent_id'])){
            $rows = $this->_list_file($_GET['parent_id']);
            $this->_json(1,'ok',$rows);
        } else {
	        $this->_json(0,'请检查参数');
	        exit();
        }
    }
//    渲染这一层的文件列表
    private function _list_file($parend_id){
	    if (isset($parend_id)){
	        $rows = [];
            $attachment_rows = \Phpcmf\Service::M()->table('attachment')->where('parent_id',$parend_id)->getAll();
            $folder_rows = \Phpcmf\Service::M()->table('attachment_folder')->where('parent_id',$parend_id)->getAll();
            $rows = array_merge($attachment_rows,$folder_rows);
            return $rows;
        } else {
            $this->_json(0,'请检查参数');
            exit();
        }
    }
}
